﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HanoiTower
{
    class Program
    {
        /// <summary>
        /// 实现将7个盘从A杆借助C杆移动到B杆
        /// </summary>
        /// <param name="args"></param>
        const int N = 7;
        static void Main(string[] args)
        {
            //运行Hanoi函数
            Hanoi(N, 'A', 'B', 'C');
            Console.ReadKey();
        }
        //将盘借C从A移动到B
        static void Hanoi(int n, char A, char B, char C)
        {


            //在一个盘的时候将其直接移动到B
            if (n == 1)
            {
                MoveStep(1, A, B);
            }

            else
            {
                //多个盘的时候先把上面n-1个从A移动到C
                Hanoi(n - 1, A, C, B);
                //再把最下面的盘从A移动到B
                MoveStep(n, A, B);
                //将上面n-1个从C移动到B
                Hanoi(n - 1, C, B, A);
            }
        }
        //输出移动路径
        static void MoveStep(int n, char A, char B)
        {
            Console.WriteLine("将第{0}个盘从{1}移动到{2}", n, A, B);
        }
    }
}
